;(function($){
	$.fn.spa_use_eCoupon = function(opts){
		var el = this;
		var opt = {
			no : "",
			multiCheck : "yes",
			brzd_array : [],
			pageTh : "",
			dataBack : function(){},
			closeBack : function(){},
		}
		var param = $.extend(opt,opts);
		var app = new App(el,param);
	}
	
	var App = function(el,param){
		this.el = el;
		this.param = param;
		this.initHtml();
		this.initPlugin();
		this.getCouponType();
		this.bindEvent();
		
	}
	
	App.prototype = {
		bindEvent : function(){
			var el = this.el;
			var param = this.param;
			var t = this;
			
			el.find("#close-dialog,#modalBtnClose").unbind("click").click(function(){
				el.modal("hide");
				el.empty();
				param.closeBack();
			});
			
			el.find("#modalBtnCheck").unbind("click").click(function(){
//				var couponid = el.find("#couponid").val();
//				t.useCoupon(couponid);
			});
			
			el.find("#couponCode_help").unbind("click").click(function(){
				t.coupon_mate();
			});
			
			//全选
			el.find("#btnChk_include_jdh").unbind("click").click(function(){
				if(el.find(".timeBox.active").size()==1){
					t.coupon_mate();
				}
			})
			
			//增加
			el.find(".btn-add").unbind("click").click(function(){
				var size = el.find(".couponid-html-container").find(".couponid-html").size();
//				t.operCouponidHtml(size+1);
				el.find("#quantity").ace_spinner('value',(size+1));
				el.find(".ace-spinner").trigger("changed.fu.spinbox");
			})
			
			el.find("input[name=autoManual]").unbind("change").change(function(){
				t.getCouponType();
			})
		},
		initHtml : function(){
			var el = this.el;
			var param = this.param;
			var t = this;
			
			var height = 500;
			
			el.addClass("modal").attr("tabindex","-2").attr("data-backdrop","static");
			var html = 	'<style>'+
							'.e-coupon-container{display:flex;} '+
							'.e-coupon-container .e-coupon-header{width:50px;text-align:right;padding:5px 5px;align-self:center;} '+
							'.e-coupon-container .e-coupon-body{flex:1;padding:5px 5px;} '+
							'.btn.btn-yellow, .btn.btn-yellow:focus {background-color: #ededed !important; border-color: #ededed !important;} '+
							'.btn-yellow.active {color: #fff !important;background-color: #2f7bba !important;border-color: #27689d !important;}'+
							'.timeBox {margin: 0px 2px 2px 0px !important;width:115px;height:40px;text-align:center;padding:0px;background-color: #ededed !important;border-color:#ededed!important;} '+
							'.timeBox.active {color: #fff !important;background-color: #2f7bba !important;border-color: #27689d !important;}'+
							'.timeBox:focus {background-color: #ededed !important; border-color: #ededed !important;} '+
							'.timeBox .timeContent{color: #996633 !important;text-overflow: ellipsis;display: -webkit-box;-webkit-line-clamp: 2;-webkit-box-orient: vertical;}'+
							'.timeBox.active .timeContent{color: #fff !important;}'+
						'</style>'+
						'<div class="modal-dialog" style="width:1080px;">'+
							'<div id="pageOverlay" class="hide"></div>'+
							'<div id="loading" class="loading hide">'+
								'<i class="ace-icon fa fa-spinner fa-spin orange bigger-250"></i>'+
							'</div>'+
							'<div class="modal-content">'+
								'<div class="modal-header no-padding">'+
									'<div class="table-header">'+
										'<button id="close-dialog" type="button" class="close" data-dismiss="modal" aria-hidden="true" value="HTML">'+
											'<span class="white">&times;</span>'+
										'</button>'+
										'<span id="modal-h4">'+$.i18n.propJsp("使用优惠券")+'</span>'+
									'</div>'+
								'</div>'+
								'<div class="modal-body">'+
									'<div class="row">'+
										'<div class="col-sm-6 no-padding-right">'+
											'<div class="widget-box">'+//transparent
												'<div class="widget-header">'+
													'<h6 class="widget-title">'+
														$.i18n.propJsp("项目")+
													'</h6>'+
													'<div class="widget-toolbar">'+
														'<label class="">'+$.i18n.propJsp("全部接待")+'</label>'+
														'<label>'+
															'<input id="btnChk_include_jdh" name="switch-field-1" class="ace ace-switch ace-switch-7" type="checkbox">'+
															'<span class="lbl" style="top: 8px;"></span>'+
														'</label>'+
													'</div>'+
												'</div>'+
												'<div id="itemContainer" class="widget-body" style="height:'+height+'px;">'+
												
												'</div>'+
											'</div>'+
										'</div>'+
										'<div class="col-sm-6 no-padding-left">'+// style="border-left: 1px solid #dce8f1;"
											'<div class="widget-box">'+//transparent
												'<div class="widget-header" style="height:39px;">'+
													'<h6 class="widget-title">'+
														$.i18n.propJsp("优惠券")+
													'</h6>'+
													'<div class="widget-toolbar">'+
														'<label style="margin-right: 10px;">'+
															'<input name="autoManual" value="0" class="ace" type="radio" checked>'+
															'<span class="lbl">'+$.i18n.propJsp("自动")+'</span>'+
														'</label>'+
														'<label >'+
															'<input name="autoManual" value="1" class="ace" type="radio">'+
															'<span class="lbl">'+$.i18n.propJsp("手动")+'</span>'+
														'</label>'+
													'</div>'+
												'</div>'+
												'<div class="widget-body" style="height:'+height+'px;">'+
													'<div class="e-coupon-container">'+
//														'<div class="e-coupon-header">'+
//															$.i18n.propJsp("类别")+
//														'</div>'+
														'<div class="e-coupon-body">'+
														
															'<div id="couponContainer" class="widget-box" style="height:'+(height-280)+'px;overflow-x:hidden;overflow-y:auto;padding-top: 2px;">'+
																
															'</div>'+
															
														'</div>'+
													'</div>'+
													'<div class="e-coupon-container">'+
														'<div class="e-coupon-header">'+
															$.i18n.propJsp("数量")+
														'</div>'+
														'<div class="e-coupon-body">'+
															'<div class="input-group" style="width:280px;float:left;">'+
																'<input id="quantity" name="quantity" maxlength="2" class="spinner"/>'+
//																'<input type="number" class="form-control search-query inputEntry" id="quantity" name="quantity" value="1">'+
															'</div>'+
														'</div>'+
													'</div>'+
													'<div class="couponid-html-container widget-box transparent no-padding no-margin" style="height:225px;overflow-y:auto;">'+//
														
														'<div class="e-coupon-container couponid-html">'+
															'<div class="e-coupon-header">'+
																$.i18n.propJsp("券号")+
															'</div>'+
															'<div class="e-coupon-body">'+
																'<div class="input-group" style="width:450px;float:left;">'+
																	'<input type="text" class="form-control search-query inputEntry" id="couponid" name="couponid">'+
																	'<span class="input-group-btn">'+
																		'<button type="button" data-name="sl" class="btn btn-primary btn-sm btn-search">'+
																			'<span class="ace-icon fa fa-search icon-on-right bigger-110"></span>'+
																			$.i18n.propJsp("查询")+
																		'</button>'+
																		'<button type="button" data-name="sl" class="btn btn-white btn-sm btn-add" style="margin-left:5px;height: 34px;">'+
																			'<span class="ace-icon fa fa-plus icon-on-right bigger-110"></span>'+
//																			$.i18n.propJsp("增加")+
																		'</button>'+
																	'</span>'+
																'</div>'+
															'</div>'+
														'</div>'+
													
													'</div>'+
												'</div>'+
											'</div>'+
										'</div>'+
									'</div>'+
								'</div>'+
								'<div class="modal-footer">'+
									'<div class="btn-group">'+
										'<button id="modalBtnCheck" type="button" class="btn btn-sm btn-info">'+
											'<i class="ace-icon fa fa-check"></i>'+$.i18n.propJsp("使用")+
										'</button>'+
									'</div>'+
									'<div class="btn-group">'+
										'<button id="modalBtnClose" type="button" class="btn btn-sm btn-default">'+
											'<i class="ace-icon fa fa-undo"></i>'+$.i18n.propJsp("返回")+
										'</button>'+
									'</div>'+
								'</div>'+
							'</div>'+
						'</div>';
			el.html(html);
		},
		initPlugin : function(){
			var el = this.el;
			var param = this.param;
			var t = this;
			
			el.find(".spinner").ace_spinner({
				value :1,
				min:1,
				max:999,
				step:1, 
				on_sides: true, 
				icon_up:'ace-icon fa fa-plus smaller-75', 
				icon_down:'ace-icon fa fa-minus smaller-75', 
				btn_up_class:'btn-success' , 
				btn_down_class:'btn-danger',
			}).closest('.ace-spinner').on('changed.fu.spinbox', function(){
				//alert($('#spinner1').val())
				setTimeout(function(){
					var num = parseInt(el.find("#quantity").val());
					t.operCouponidHtml(num);
				},10)
			});
		},
		getCouponType : function(){
			var el = this.el;
			var param = this.param;
			var t = this;
			var ds = sysgetdict("#优惠券");
			var sortbys="";
    		var itemDom=el.find("#couponContainer"); 
    		itemDom.empty();
			var autoManual = el.find("input[name=autoManual]:checked").val();
    		var queryt = "select * from json where (descript2=='"+autoManual+"') order by sortbys";// 

    		var ds1 = jsonsql.query(queryt,ds);
    		var html = ""
    		
    		var sortbys = 'startFor000';//用来区分是否是第一个循环
    		ds1.map(x => {
    			
    			if(sortbys=='startFor000'){
    				sortbys = x.sortbys;
    				html = '<div style="display:flex !important;margin-bottom:3px;">'+
								'<div class="sortbysTitle" style="width:18px;display:flex;flex-direction:column;justify-content:center;align-items:center;font-size:12px;font-weight:bold;background:#b5d1e2;border-bottom: 1px solid #f5f5f5;text-align:center;">'+
									sortbys+
								'</div>'+
								'<div class="sortbysLine clearfix" id="sortbys-1" style="flex:1;padding-left:5px;display:flex;flex-wrap: wrap;">';
//									'<span data-toggle="buttons" class="btn-group" style="padding-left:5px;">';
										
    			}else if(sortbys!=x.sortbys){
    				sortbys = x.sortbys;
							
    				html +=	'</span></div></div>'+
							'<div style="display:flex !important;margin-bottom:3px;">'+
								'<div class="sortbysTitle" style="width:18px;display:flex;flex-direction:column;justify-content:center;align-items:center;font-size:12px;font-weight:bold;background:#b5d1e2;border-bottom: 1px solid #f5f5f5;text-align:center;">'+
									sortbys+
								'</div>'+
								'<div class="sortbysLine clearfix" id="sortbys-1" style="flex:1;padding-left:5px;display:flex;flex-wrap: wrap;">';
//									'<span data-toggle="buttons" class="btn-group" style="padding-left:5px;">';
    			}
			
//    			html +=	'<label data-code="'+x.code+'" data-name="coupon" class="timeBox btn btn-yellow">'+
//								'<span class="ui-button-text">'+
//									'<input type="radio" name="ktjs_option" value="">'+
//									'<span>'+x.descript1+'</span>'+
//								'</span>'+
//							'</label>';
				
				var clone = $('<span>'+x.descript1+'</span>');
			    clone.css("visibility","hidden");
			    $('body').append(clone);
			    var width = clone.width();
			    clone.remove();
			 	var lineHeight = "40px;";
				if(width>115){
					lineHeight = "20px;"
				}
				html +=	'<div data-code="'+x.code+'" data-name="coupon" class="timeBox">'+
							'<div class="timeContent" style="line-height:'+lineHeight+'" title="'+x.descript1+'">'+x.descript1+'</div>'+
						'</div>';
    			
    		});
    		
//    		html += '</span></div></div>';
			html += '</div></div>';
    		itemDom.html(html);

			el.find(".timeBox").unbind("click").click(function(){
				el.find(".timeBox").removeClass("active");
				$(this).addClass("active");
				var code = $(this).data("code");
				param.cpcode = code;
				t.coupon_mate();
//				el.find("#couponCode").val(code);
				
			})
		},
		coupon_mate : function(){//SPAOrderCoupon_mate
			var el = this.el;
			var param = this.param;
			var t = this;
			t.wait();
			
			var chk_include_jdh = el.find("#btnChk_include_jdh").is(":checked")?"yes":"no"
			var str={"arg":{"cpcode":param.cpcode,"no":param.no,
							"quantity":el.find("#quantity").val(),"chk_include_jdh":chk_include_jdh}};
			jQuery.ajax({
				type : 'POST',
				url : $.HSAPI_AJAXURL+"/qms/mobile/procedure2",
				data : $.HSAPI_ASKJSONINFO( JSON.stringify(str),'SPAOrderCoupon_mate','{}'),
				dataType : 'json',  
				success : function(data){
					t.goon();
		            if(data.RETURN == 1){
						param.xsxm_jdh_array = data.ct_brxsxm_jdh;
						param.brzd_array = data.ct_brzd_jdh;
						t.initItemHtml();
		            }else{
		            	if(data.hasOwnProperty("gritter")){
							if(data.hasOwnProperty("gritterstyle"))
								jf_successDelayed(data.gritter,2000,data.gritterstyle);
							else
								jf_successDelayed(data.gritter,2000); 
						}else{
		    				jf_alert(data.MSG)
						}
					}
				},  
				error : function(data){ 
					t.goon(); 
					jf_alert(JSON.stringify(data))
				}  
			});
		},
		initItemHtml : function(){
			var el = this.el;
			var param = this.param;
			var t = this;
			el.find("#itemContainer").empty();
			
			var csstext = 	'<style>'+
								'.rightXsxmTitle{cursor: pointer;width:80px;display:flex;flex-direction:column;align-items:center;font-size:16px;background:#ededed;border-bottom: 1px solid #f5f5f5;margin:0px auto;}'+
								'.rightXsxmTitleSpan{word-break:break-all;line-height: 17px;color:#2b8ccc;}'+
								'.right_xsxm_box{cursor: pointer;float: left;border: 1.5px solid #e2d8d8;border-radius: 3px;position: relative;margin:0px 2px 2px 0px;height: auto;padding: 4px 5px;}'+
								'.right_xsxm_box.active{border: 1.5px solid #2b8ccc;}'+
								'.right_xsxm_box_line1,.right_xsxm_box_line2,.right_xsxm_box_line3{height: 100%;float:left;margin-right:10px;}'+
							'</style>';
			$(csstext).appendTo('.row')
			
			
//			var width = (el.width()-20-20)/5
//			var height = (el.height()-20-28)/7
			
			el.find("#itemContainer").empty()
			var boxHtml = '<div class="xsxmTh_container" style="height:100%;width:100%;overflow-y:auto;overflow-x:hidden;"></div>';
			el.find("#itemContainer").append(boxHtml);
			
			var brzd_json = {};
			$(param.brzd_array).each(function(k,v){
				brzd_json[v.th] = v;
			})
			
			$.each(param.xsxm_jdh_array,function(key,value){
				if(el.find(".xsxmTh_box[data-no='"+value.no+"']").size()<=0){
					var title  = brzd_json[value.ct_brzd_th]

					var handpanel_info = JSON.parse(title.handpanel_info)
					var th = '<span class="" style="">'+title.th+'</span>'
					var je = '<span class="" style="">'+title.xfje+'</span>'
					var dfje = ''
					if(Number(title.dfje)!=0){
						dfje = 	'<span class="" style="">('+title.dfje+')</span>';
					}
					var ico_info = JSON.parse(title.ico_info)
					var ico_info_text = ""
						$.each(ico_info,function(key,value){
							if(JSON.stringify(value)!="{}"){
								ico_info_text += getTextStyle(value);
							}
						})
					
					var html = 	'<div class="xsxmTh_box" data-no="'+value.no+'" data-th="'+value.ct_brzd_th+'" style="display:flex !important;margin-bottom:4px;border-bottom: 1px solid #E8E8E8;">'+
									'<div class="rightXsxmTitle" style="min-height:60px;width:100px;background:'+handpanel_info.bgcolor+' !important;">'+
										'<div class="line1" style="width: 100%;height:20px;line-height: 20px;float: left;">'+
											'<span style="color:'+handpanel_info.tcolor+' !important;font-size: 13px;">'+th+'</span>'+
											'<small class="text-muted" style="color:'+handpanel_info.tcolor+' !important; font-size:60%;  float:right;">'+
												ico_info_text+
											'</small>'+
										'</div>'+
										'<div class="line2" style="width: 100%;height:20px;line-height: 20px;float: left;text-align: right;">'+
											'<span style="color:'+handpanel_info.tcolor+' !important;font-size: 13px;">'+je+'</span>'+
										'</div>'+
										'<div class="line3" style="width: 100%;height:20px;line-height: 20px;float: left;text-align: right;">'+
											'<span style="color:'+handpanel_info.tcolor+' !important;font-size: 13px;">'+dfje+'</span>'+
										'</div>'+
//										'<span class="rightXsxmTitleSpan">'+
//											
//										value.ct_brzd_th+
//										'</span>'+
									'</div>'+
									'<div class="xsxmLine clearfix" data-xsxm_no="xsxm_'+value.no+'" style="flex:1;padding-left:2px">'+
									'</div>'+
								'<div>';
					el.find(".xsxmTh_container").append(html)			
				}
				
				var info = JSON.parse(value.info)
				var dis_info = JSON.parse(value.dis_info)
				var info_text = ""
				$.each(info,function(key,value){
					if(JSON.stringify(value)!="{}"){
						info_text += getTextStyle(value);
					}
				})
				
				$.each(dis_info,function(key,value){
					if(JSON.stringify(value)!="{}"){
						info_text += getTextStyle(value);
					}
				})
				
				var panel_info =  JSON.parse(value.panel_info)
				var bgcolor = (panel_info['bgcolor']?panel_info['bgcolor']:"white")
				var tcolor = (panel_info['tcolor']?panel_info['tcolor']:"")
				
				var active = "";
				if(value.sele==1){
					active = "active";
				}
				
				var xsxmhtml = 	'<div class="right_xsxm_box '+active+'" data-bh="'+value.bh+'" data-xh="'+value.xh+'" data-th="'+value.ct_brzd_th+'"  data-mess="'+encodeURIComponent(JSON.stringify(value))+'" style="background-color:'+bgcolor+';color:'+tcolor+';">'+
									'<div class="right_xsxm_box_line3" style="display: flex;">'+
										info_text+
									'</div>'+
								'</div>';
				$(".xsxmLine[data-xsxm_no='xsxm_"+value.no+"']").append(xsxmhtml)
				
				var index = $(".xsxmLine[data-xsxm_no='xsxm_"+value.no+"'] div[data-th='"+value.ct_brzd_th+"']").size()
				$(".xsxmLine[data-xsxm_no='xsxm_"+value.no+"']").find("div[data-xh='"+value.xh+"']").find("span:eq(0)").prepend(index+".")
			})
			
			t.retrievePayable();
			t.bindrightXsxmEvent();
		},
		bindrightXsxmEvent : function(){
			var el = this.el;
			var param = this.param;
			var t = this;
			
			el.find(".right_xsxm_box").unbind("dblclick").dblclick(function(){
				var json = JSON.parse(decodeURIComponent($(this).attr("data-mess")))
//				param.dblClickBack(json);
			})
			
			if(param.multiCheck=="yes"){
				el.find(".right_xsxm_box").unbind("click").click(function(){
					if($(this).hasClass("active")){
						$(this).removeClass("active")
					}else{
						$(this).addClass("active")
					}
					if( $(this).parent("div").find(".right_xsxm_box.active").size()>0 && !$(this).parent("div").parent("div").find(".rightXsxmTitle").hasClass("active") ){
						$(this).parent("div").parent("div").find(".rightXsxmTitle").addClass("active")
						var html = '<div class="ifCheck" style="float:left"><i class="fa fa-check" style="zoom: 120%;color:#59d245" aria-hidden="true"></i></div>'
						$(this).parent("div").parent("div").find(".rightXsxmTitle").find(".line3").prepend(html)
					}
					if(0 == $(this).parent("div").find(".right_xsxm_box.active").size()){
						if(param.pageTh!="" && $(this).parent("div").parent("div").attr("data-th")!=param.pageTh){
							$(this).parent("div").parent("div").find(".rightXsxmTitle").removeClass("active")
							$(this).parent("div").parent("div").find(".rightXsxmTitle").find(".line3 .ifCheck").remove()
						}
						
					}
					t.retrievePayable();
				})
				
				el.find(".rightXsxmTitle").unbind("click").click(function(){
					if($(this).hasClass("active")){
						if($(this).parent("div").find(".right_xsxm_box").size() == $(this).parent("div").find(".right_xsxm_box.active").size()){
							$(this).parent("div").find(".right_xsxm_box").removeClass("active")
							
							if(param.pageTh!="" && $(this).parent("div").attr("data-th")!=param.pageTh){
								$(this).find(".line3 .ifCheck").remove()
								$(this).removeClass("active")
							}
						}else{
							$(this).parent("div").find(".right_xsxm_box").addClass("active")
						}
					}else{
						var html = '<div class="ifCheck" style="float:left"><i class="fa fa-check" style="zoom: 120%;color:#59d245" aria-hidden="true"></i></div>'
						$(this).find(".line3").prepend(html)
						$(this).addClass("active")
						$(this).parent("div").find(".right_xsxm_box").addClass("active")
					}
					t.retrievePayable();
				})
			}else{
				el.find(".right_xsxm_box").unbind("click").click(function(){
					el.find(".right_xsxm_box").removeClass("active")
					$(this).addClass("active")
					t.retrievePayable();
				})
			}
		},
		//获取应付数值
		retrievePayable:function(){
			var el = this.el;
			var param = this.param;
			var t = this;
			
			var payTotal = 0
			if(param.multiCheck=="yes"){
				if(el.find(".rightXsxmTitle.active").size()<=0){
					el.find(".right_xsxm_box").each(function(){
						var json = JSON.parse(decodeURIComponent($(this).attr("data-mess")))
						payTotal = (Number(payTotal) + Number(json.amount)).toFixed(2)
					})
				}else{
					el.find(".rightXsxmTitle.active").each(function(){
						$(this).parent("div").find(".right_xsxm_box.active").each(function(){
							var json = JSON.parse(decodeURIComponent($(this).attr("data-mess")))
							payTotal = (Number(payTotal) + Number(json.amount)).toFixed(2)
						})
					})
				}
			}else{
				var className = ".right_xsxm_box.active"
				if(el.find(".right_xsxm_box.active").size()<=0){
					className = ".right_xsxm_box"
				}else{
					className = ".right_xsxm_box.active"
				}
				el.find(className).each(function(){
					var json = JSON.parse(decodeURIComponent($(this).attr("data-mess")))
					payTotal = (Number(payTotal) + Number(json.amount)).toFixed(2)
				})
			}
//			param.clickBack(payTotal)
		},
		useCoupon : function(couponid,paramer){
			var el = this.el;
			var param = this.param;
			var t = this;
			
			//构造参数
    		var pa={};
    		if(paramer){
    			pa.arg={};
    			pa.arg=$.extend({},pa.arg,paramer); 
    			t.wait();
    			$.post($.HSAPI_AJAXURL+"/qms/mobile/procedure2",  
					  $.HSAPI_ASKJSONINFO(JSON.stringify(pa),'HoMemberCoupon_Active','{}'),   
					  function(data){
        				t.goon();
    					if(data.RETURN==1){ 
							el.modal("hide");
							el.empty();
    						param.dataBack();
    					}else if(data.RETURN=="-10"){ 
    						t.errorContent(pa.arg,data,couponid);  
    					}else if(data.RETURN=="-11"){ 
    						t.errorContent_11(pa.arg,data,couponid);  
    					}else{
    						jf_alert(data.MSG);
    					}
    			},"json"); 
    		}else{
    			pa.arg={arg:param.arg,operation:"actived"};
    			if(param.arg=="rm"){
    				pa.arg.gno = param.gno
    			}else if(param.arg=="pos"){
    				pa.arg.no = param.no
    			}
        		pa.arg=$.extend({},pa.arg,{"couponid":couponid,mno:param.mno});//,"remark":el.find("#remark").val()   
        		if(couponid){
        			//二维码
        			$("#smscode").modalFrame("destroy");
        			$("#smscode").modalFrame("init",function(modalEle){
        				if(!$.isFunction($().smscode)){
        					$.ajaxSetup({ async: false, cache: false });
        		            $.getScript("js/cashier_mana/jquery.modal.smscode.js");
        		            $.ajaxSetup({ async: true });
        				}
        		    	$("#"+modalEle).smscode({
        		    		couponid:couponid,
        		    		dataBack : function(data){
        		    			$("#"+modalEle).modal("hide");
        		    			$("#"+modalEle).empty();
        		    			pa.arg["smscode"]=data;
								t.useCoupon(couponid,pa.arg)
        		    		},
        		    		returnBack : function(){
        		    			$("#"+modalEle).modal("hide");
        		    			$("#"+modalEle).empty();
        		    			t.goon();
        		    		},
        		    	});
        			})
        		}else{
        			jf_alert($.i18n.propJsp("请选择一张电子券")+"！")
        		}
    		}
		},
		//出错提示
    	errorContent : function(pa,data,couponid){
    		var t=this;
    		var param=this.param; 
    		var el=this.el;  
    		
    		var MSG = data.MSG;
    		var name = data.checkbox;
    		
    		
    		var html = 	'<h3 class="header smaller lighter blue">'+
    						'<i class="ace-icon fa fa-bullhorn"></i>'+MSG+
    					'</h3>'+
    					'<div class="alert alert-block alert-danger">'+
    						'<label>'+
    							'<input id="checkin_cccheckbox" type="checkbox" name="'+name+'" value="" class="ace"/>'+ 
    							'<span class="lbl" style="color:#478fca;">'+MSG+'</span>'+
    						'</label>'+
    					'</div>';

    		bootbox.dialog({
    			message: html,
    			buttons:{
    				"button1":{
    					"label" : $.i18n.propJsp("确定"),
    					"className" : "btn-sm btn-info",
    					"callback" : function(){
    						if($("#checkin_cccheckbox").prop("checked")){
    							pa[name]="yes";
    						}else{
    							pa[name]="no";
    						}
							t.useCoupon(couponid,pa.arg)  
    					}
    				},	
    				"button" :
    				{
    					"label" : $.i18n.propJsp("取消"),
    					"className" : "btn-sm",
    				},
    			}
    		});
    	},
    	//出错提示-11
    	errorContent_11 : function(pa,data,couponid){
    		var t=this;
    		var param=this.param; 
    		var el=this.el;  
    		
    		var name = data.radiobutton
    		
    		$("#save").modalFrame("destroy");
			$("#save").modalFrame("init",function(modalEle){
				if(!$.isFunction($().RETURN_11)){
					$.ajaxSetup({ async: false, cache: false });
		            $.getScript("js/cashier_mana/jquery.RETURN_11.js");
		            $.ajaxSetup({ async: true });
				}
		    	$("#"+modalEle).RETURN_11({
		    		data:data,
		    		dataBack : function(data){
		    			$("#"+modalEle).modal("hide");
		    			$("#"+modalEle).empty();
		    			pa[name]=data;
						t.useCoupon(couponid,pa.arg);    
		    		},
		    		returnBack : function(){
		    			$("#"+modalEle).modal("hide");
		    			$("#"+modalEle).empty();
		    			t.useCoupon(couponid,pa.arg);  
		    		},
		    	});
			})
    	},
		operCouponidHtml : function(num){
			var el = this.el;
			var param = this.param;
			var t = this;
			var size = el.find(".couponid-html").size();
			num = parseInt(el.find("#quantity").val());
			if(num<1){
				num = 1;
			}
			if(size>num){
				for(var i=size;i>num;i--){
					el.find(".couponid-html-container").find(".couponid-html").eq(i-1).remove();
				}
			}else if(size<num){
				
				for(var i=size;i<num;i++){
					var clone = el.find(".couponid-html-container").find(".couponid-html").eq(0);
					var html = '<div class="e-coupon-container couponid-html">'+clone.html()+'</div>'
				 	el.find(".couponid-html-container").append(html);	
				}
			}
			//增加
			el.find(".btn-add").unbind("click").click(function(){
				var size = el.find(".couponid-html-container").find(".couponid-html").size();
//				t.operCouponidHtml(size+1);
				el.find("#quantity").ace_spinner('value',(size+1));
				el.find(".ace-spinner").trigger("changed.fu.spinbox");
			})			
		},
		goon : function(){
			var el = this.el;
			el.find("#loading").addClass("hide");
			el.find("#pageOverlay").addClass("hide");
		},
		wait : function(){
			var el = this.el;
			el.find("#loading").removeClass("hide");
			el.find("#pageOverlay").removeClass("hide");
		},
	}
	
})(jQuery);